home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2010 April / PCWorld0410.iso / hity wydania / GIMP 2.6.8 / gimp-2.6.8-i686-setup.exe / {app} / share / gimp / 2.0 / scripts / slide.scm < prev    next >
Text File  |  2009-12-15  |  10KB  |  257 lines

  1. ; GIMP - The GNU Image Manipulation Program
  2. ; Copyright (C) 1995 Spencer Kimball and Peter Mattis
  3. ;
  4. ; This program is free software; you can redistribute it and/or modify
  5. ; it under the terms of the GNU General Public License as published by
  6. ; the Free Software Foundation; either version 2 of the License, or
  7. ; (at your option) any later version.
  8. ;
  9. ; This program is distributed in the hope that it will be useful,
  10. ; but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12. ; GNU General Public License for more details.
  13. ;
  14. ; You should have received a copy of the GNU General Public License
  15. ; along with this program; if not, write to the Free Software
  16. ; Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  17. ;
  18. ;
  19. ; slide.scm   version 0.41   2004/03/28
  20. ;
  21. ; CHANGE-LOG:
  22. ; 0.20 - first public release
  23. ; 0.30 - some code cleanup
  24. ;        now uses the rotate plug-in to improve speed
  25. ; 0.40 - changes to work with gimp-1.1
  26. ;        if the image was rotated, rotate the whole thing back when finished
  27. ; 0.41 - changes to work with gimp-2.0, slightly correct text offsets,
  28. ;        Nils Philippsen <nphilipp@redhat.com> 2004/03/28
  29. ;
  30. ; !still in development!
  31. ; TODO: - change the script so that the film is rotated, not the image
  32. ;       - antialiasing
  33. ;       - make 'add background' an option
  34. ;       - ?
  35. ;
  36. ; Copyright (C) 1997-1999 Sven Neumann <sven@gimp.org>
  37. ;
  38. ; makes your picture look like a slide
  39. ;
  40. ; The script works on RGB and grayscale images that contain only
  41. ; one layer. The image is cropped to fit into an aspect ratio of 1:1,5.
  42. ; It creates a copy of the image or can optionally work on the original.
  43. ; The script uses the current background color to create a background
  44. ; layer.
  45.  
  46.  
  47. (define (script-fu-slide img
  48.                          drawable
  49.                          text
  50.                          number
  51.                          fontname
  52.                          font-color
  53.                          work-on-copy)
  54.  
  55.   (define (crop width height ratio)
  56.     (if (>= width (* ratio height))
  57.         (* ratio height)
  58.         width
  59.     )
  60.   )
  61.  
  62.   (let* (
  63.         (type (car (gimp-drawable-type-with-alpha drawable)))
  64.         (image (cond ((= work-on-copy TRUE)
  65.                       (car (gimp-image-duplicate img)))
  66.                      ((= work-on-copy FALSE)
  67.                       img)))
  68.         (owidth (car (gimp-image-width image)))
  69.         (oheight (car (gimp-image-height image)))
  70.         (ratio (if (>= owidth oheight) (/ 3 2)
  71.                                        (/ 2 3)))
  72.         (crop-width (crop owidth oheight ratio))
  73.         (crop-height (/ crop-width ratio))
  74.         (width (* (max crop-width crop-height) 1.05))
  75.         (height (* (min crop-width crop-height) 1.5))
  76.         (hole-width (/ width 20))
  77.         (hole-space (/ width 8))
  78.         (hole-height (/ width 12))
  79.         (hole-radius (/ hole-width 4))
  80.         (hole-start (- (/ (rand 1000) 1000) 0.5))
  81.         (film-layer (car (gimp-layer-new image
  82.                                          width
  83.                                          height
  84.                                          type
  85.                                          "Film"
  86.                                          100
  87.                                          NORMAL-MODE)))
  88.         (bg-layer (car (gimp-layer-new image
  89.                                        width
  90.                                        height
  91.                                        type
  92.                                        "Background"
  93.                                        100
  94.                                        NORMAL-MODE)))
  95.         (pic-layer (car (gimp-image-get-active-drawable image)))
  96.         (numbera (string-append number "A"))
  97.         )
  98.  
  99.   (gimp-context-push)
  100.  
  101.   (gimp-image-undo-disable image)
  102.  
  103. ; add an alpha channel to the image
  104.   (gimp-layer-add-alpha pic-layer)
  105.  
  106. ; crop, resize and eventually rotate the image
  107.   (gimp-image-crop image
  108.                    crop-width
  109.                    crop-height
  110.                    (/ (- owidth crop-width) 2)
  111.                    (/ (- oheight crop-height) 2))
  112.   (gimp-image-resize image
  113.                      width
  114.                      height
  115.                      (/ (- width crop-width) 2)
  116.                      (/ (- height crop-height) 2))
  117.   (if (< ratio 1)
  118.       (plug-in-rotate RUN-NONINTERACTIVE image pic-layer 1 FALSE)
  119.   )
  120.  
  121. ; add the background layer
  122.   (gimp-drawable-fill bg-layer BACKGROUND-FILL)
  123.   (gimp-image-add-layer image bg-layer -1)
  124.  
  125. ; add the film layer
  126.   (gimp-context-set-background '(0 0 0))
  127.   (gimp-drawable-fill film-layer BACKGROUND-FILL)
  128.   (gimp-image-add-layer image film-layer -1)
  129.  
  130. ; add the text
  131.   (gimp-context-set-foreground font-color)
  132.   (gimp-floating-sel-anchor (car (gimp-text-fontname image
  133.                                             film-layer
  134.                                             (+ hole-start (* -0.25 width))
  135.                                             (* 0.01 height)
  136.                                             text
  137.                                             0
  138.                                             TRUE
  139.                                             (* 0.040 height) PIXELS fontname)))
  140.   (gimp-floating-sel-anchor (car (gimp-text-fontname image
  141.                                             film-layer
  142.                                             (+ hole-start (* 0.75 width))
  143.                                             (* 0.01 height)
  144.                                             text
  145.                                             0
  146.                                             TRUE
  147.                                             (* 0.040 height) PIXELS
  148.                                             fontname )))
  149.   (gimp-floating-sel-anchor (car (gimp-text-fontname image
  150.                                             film-layer
  151.                                             (+ hole-start (* 0.35 width))
  152.                                             0.0
  153.                                             number
  154.                                             0
  155.                                             TRUE
  156.                                             (* 0.050 height) PIXELS
  157.                                             fontname )))
  158.   (gimp-floating-sel-anchor (car (gimp-text-fontname image
  159.                                             film-layer
  160.                                             (+ hole-start (* 0.35 width))
  161.                                             (* 0.94 height)
  162.                                             number
  163.                                             0
  164.                                             TRUE
  165.                                             (* 0.050 height) PIXELS
  166.                                             fontname )))
  167.   (gimp-floating-sel-anchor (car (gimp-text-fontname image
  168.                                             film-layer
  169.                                             (+ hole-start (* 0.85 width))
  170.                                             (* 0.945 height)
  171.                                             numbera
  172.                                             0
  173.                                             TRUE
  174.                                             (* 0.045 height) PIXELS
  175.                                             fontname )))
  176.  
  177. ; create a mask for the holes and cut them out
  178.   (let* (
  179.         (film-mask (car (gimp-layer-create-mask film-layer ADD-WHITE-MASK)))
  180.         (hole hole-start)
  181.         (top-y (* height 0.06))
  182.         (bottom-y (* height 0.855))
  183.         )
  184.  
  185.     (gimp-layer-add-mask film-layer film-mask)
  186.  
  187.     (gimp-selection-none image)
  188.     (while (< hole 8)
  189.            (gimp-rect-select image
  190.                              (* hole-space hole)
  191.                              top-y
  192.                              hole-width
  193.                              hole-height
  194.                              CHANNEL-OP-ADD
  195.                              FALSE
  196.                              0)
  197.            (gimp-rect-select image
  198.                              (* hole-space hole)
  199.                              bottom-y
  200.                              hole-width
  201.                              hole-height
  202.                              CHANNEL-OP-ADD
  203.                              FALSE
  204.                              0)
  205.            (set! hole (+ hole 1))
  206.     )
  207.  
  208.     (gimp-context-set-foreground '(0 0 0))
  209.     (gimp-edit-fill film-mask BACKGROUND-FILL)
  210.     (gimp-selection-none image)
  211.     (plug-in-gauss-rle RUN-NONINTERACTIVE image film-mask hole-radius TRUE TRUE)
  212.     (gimp-threshold film-mask 127 255)
  213.  
  214.     (gimp-layer-remove-mask film-layer MASK-APPLY)
  215.   )
  216.  
  217. ; reorder the layers
  218.   (gimp-image-raise-layer image pic-layer)
  219.   (gimp-image-raise-layer image pic-layer)
  220.  
  221. ; eventually rotate the whole thing back
  222.   (if (< ratio 1)
  223.       (plug-in-rotate RUN-NONINTERACTIVE image pic-layer 3 TRUE)
  224.   )
  225.  
  226. ; clean up after the script
  227.   (gimp-selection-none image)
  228.   (gimp-image-undo-enable image)
  229.   (if (= work-on-copy TRUE)
  230.       (gimp-display-new image)
  231.   )
  232.  
  233.   (gimp-displays-flush)
  234.  
  235.   (gimp-context-pop)
  236.   )
  237. )
  238.  
  239. (script-fu-register "script-fu-slide"
  240.   _"_Slide..."
  241.   _"Add a slide-film like frame, sprocket holes, and labels to an image"
  242.   "Sven Neumann <sven@gimp.org>"
  243.   "Sven Neumann"
  244.   "2004/03/28"
  245.   "RGB GRAY"
  246.   SF-IMAGE     "Image"         0
  247.   SF-DRAWABLE  "Drawable"      0
  248.   SF-STRING   _"Text"          "GIMP"
  249.   SF-STRING   _"Number"        "32"
  250.   SF-FONT     _"Font"          "Serif"
  251.   SF-COLOR    _"Font color"    '(255 180 0)
  252.   SF-TOGGLE   _"Work on copy"  TRUE
  253. )
  254.  
  255. (script-fu-menu-register "script-fu-slide"
  256.                          "<Image>/Filters/Decor")
  257.